package com.fdb.efp.nls.service.impl;

import com.alibaba.fastjson.JSON;
import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.FileNoticeRecordDao;
import com.fdb.efp.nls.service.domain.FileNoticeRecord;
import com.fdb.efp.nls.service.facade.FileNoticeRecordService;
import com.fdb.efp.nls.service.vo.FileNoticeRecordVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 文件通知记录表<p>
 * @author ligm
 * @date 2019-05-13
 */
@Service("fileNoticeRecordService")
public class FileNoticeRecordServiceImpl implements FileNoticeRecordService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(FileNoticeRecordServiceImpl.class);

	@Autowired
	private FileNoticeRecordDao fileNoticeRecordDao;
	
	/**
	 * 新增操作
	 */
	public int insertFileNoticeRecord(FileNoticeRecordVO inFileNoticeRecordVo) {
		logger.debug("当前新增数据为:"+ inFileNoticeRecordVo.toString());
		int num = 0;
		try {
			FileNoticeRecord fileNoticeRecord = new FileNoticeRecord();
			beanCopy(inFileNoticeRecordVo, fileNoticeRecord);
			num = fileNoticeRecordDao.insertFileNoticeRecord(fileNoticeRecord);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(FileNoticeRecordVO inFileNoticeRecordVo) {
		logger.debug("当前删除数据条件为:"+ inFileNoticeRecordVo);
		int num = 0;
		try {
			FileNoticeRecord fileNoticeRecord = new FileNoticeRecord();
			beanCopy(inFileNoticeRecordVo, fileNoticeRecord);
			num = fileNoticeRecordDao.deleteByPk(fileNoticeRecord);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inFileNoticeRecordVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(FileNoticeRecordVO inFileNoticeRecordVo) {
		logger.debug("当前修改数据为:"+ inFileNoticeRecordVo.toString());
		int num = 0;
		try {
			FileNoticeRecord fileNoticeRecord = new FileNoticeRecord();
			beanCopy(inFileNoticeRecordVo, fileNoticeRecord);
			num = fileNoticeRecordDao.updateByPk(fileNoticeRecord);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inFileNoticeRecordVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public FileNoticeRecordVO queryByPk(FileNoticeRecordVO inFileNoticeRecordVo) {
		
		logger.debug("当前查询参数信息为:"+ inFileNoticeRecordVo);
		try {
			FileNoticeRecord queryFileNoticeRecord = new FileNoticeRecord();
			beanCopy(inFileNoticeRecordVo, queryFileNoticeRecord);
			FileNoticeRecord queryRslFileNoticeRecord = fileNoticeRecordDao.queryByPk(queryFileNoticeRecord);
			if (Objects.nonNull(queryRslFileNoticeRecord)) {
				FileNoticeRecordVO outFileNoticeRecordVo = beanCopy(queryRslFileNoticeRecord, new FileNoticeRecordVO());
				logger.debug("当前查询结果为:"+ outFileNoticeRecordVo.toString());
				return outFileNoticeRecordVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<FileNoticeRecordVO> queryAllOwner(FileNoticeRecordVO fileNoticeRecordVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<FileNoticeRecordVO> list = null;
		try {
			List<FileNoticeRecord> fileNoticeRecords = fileNoticeRecordDao.queryAllOwnerByPage(fileNoticeRecordVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ fileNoticeRecords.size());
			pageSet(fileNoticeRecords, fileNoticeRecordVo);
			list = (List<FileNoticeRecordVO>) beansCopy(fileNoticeRecords, FileNoticeRecordVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<FileNoticeRecordVO> queryAllCurrOrg(FileNoticeRecordVO fileNoticeRecordVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<FileNoticeRecord> fileNoticeRecords = fileNoticeRecordDao.queryAllCurrOrgByPage(fileNoticeRecordVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+fileNoticeRecords.size());
		List<FileNoticeRecordVO> list = null;
		try {
			pageSet(fileNoticeRecords, fileNoticeRecordVo);
			list = (List<FileNoticeRecordVO>) beansCopy(fileNoticeRecords, FileNoticeRecordVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<FileNoticeRecordVO> queryAllCurrDownOrg(FileNoticeRecordVO fileNoticeRecordVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<FileNoticeRecord> fileNoticeRecords = fileNoticeRecordDao.queryAllCurrDownOrgByPage(fileNoticeRecordVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ fileNoticeRecords.size());
		List<FileNoticeRecordVO> list = null;
		try {
			pageSet(fileNoticeRecords, fileNoticeRecordVo);
			list = (List<FileNoticeRecordVO>) beansCopy(fileNoticeRecords, FileNoticeRecordVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	@Override
	public FileNoticeRecordVO queryByCondition(FileNoticeRecordVO fileNoticeRecordVo) {
		logger.debug("当前查询参数信息为: "+ JSON.toJSONString(fileNoticeRecordVo));
		try {
			FileNoticeRecord queryFileNoticeRecord = new FileNoticeRecord();
			beanCopy(fileNoticeRecordVo, queryFileNoticeRecord);
			FileNoticeRecord queryRslFileNoticeRecord = fileNoticeRecordDao.queryByPk(queryFileNoticeRecord);
			if (Objects.nonNull(queryRslFileNoticeRecord)) {
				FileNoticeRecordVO result = beanCopy(queryRslFileNoticeRecord, new FileNoticeRecordVO());
				logger.debug("当前查询结果为:"+ JSON.toJSONString(result));
				return result;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}
	
}
